<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>分享存档</title>
    <link rel="stylesheet" type="text/css" href="baye.css" />
    <link rel="icon" href="favicon.png">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" id="viewport" name="viewport">
    <style>
        .btn.menu {
            margin-bottom: 2px;
        }
        #url {
            font-size: 30px;
        }
    </style>
</head>
<body>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
    <script src="js/lzma_worker-min.js"></script>
    <script src="js/base64.js"></script>
    <script>
        function getfile(n) {
            return localStorage["baye//data//sango" + n + ".sav"];
        }

        function dump(n) {
            return getfile(n*2) + '.' + getfile(n*2+1);
        }

        function upload(n) {
            var self = $(this);
            var data = dump(n);

            $("#osize").html('origin:' + data.length);

            if (data.length < 100) {
                $("#url-title").html("");
                $("#url").html("该存档为空!");
                return;
            }

            $("#result").html("请求中...");
            var result = LZMA.compress(data, 9);

            var b64data = Base64.encode(result);

            $("#zsize").html('result:' + result.length);
            $("#bsize").html('b64data:' + b64data.length);

            var loadUrl = "http://bgwp.oschina.io/baye/load.html?sav=" + b64data;

            $.ajax({
                url: "http://50r.cn/urls/add.jsonp?url=" + loadUrl,
                dataType: "jsonp",
                jsonp: "callback",
                jsonpCallback: "www_50r_cn_jsonp_callback",
                type: "GET",
                success: function(resp) {
                    $("#url-title").html("已生成存档" + (n + 1) + "的链接:");
                    $("#url").html('<a href="' + resp.url + '">' + resp.url + '</a>');
                },
                error: function() {
                    $("#url-title").html("");
                    $("#url").html("请求失败");
                }
            });
        }
    </script>

    <button class="btn menu" type="button" onclick="upload(0)">导出存档1</button>
    <button class="btn menu" type="button" onclick="upload(1)">导出存档2</button>
    <button class="btn menu" type="button" onclick="upload(2)">导出存档3</button>

    <div >
        <div id="url-title"></div>
        <div id="url"></div>
        <br>
        <div id="osize"></div>
        <div id="zsize"></div>
        <div id="bsize"></div>
    </div>

</body>
</html>
